//
//  UIImage+Extension.swift
//  Weibo
//
//  Created by ios on 16/8/17.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit
extension UIImage{
//等比压缩图片
func scaleImageWithScaleWidth(ScaleWidth:CGFloat) -> UIImage{
    //  计算等比压缩后的高度
    let  ScaleHeight = ScaleWidth / self.size.width * self.size.height
    let size = CGSize(width: ScaleWidth, height: ScaleHeight)
    //开启图片上下文
    
    UIGraphicsBeginImageContext(size)
    //  图片绘制到指定区域内
    self.drawInRect(CGRect(origin: CGPointZero, size: size))
    //获取压缩后的图片
    let ScaleImg = UIGraphicsGetImageFromCurrentImageContext()
    //关闭图片上下文
    UIGraphicsEndImageContext()
    
    return ScaleImg
}

}